#!/usr/bin/python
# -*- coding: utf-8 -*-

import MySQLdb

conn = MySQLdb.Connection("172.16.7.58", "root", "researchsucks", "X", 3306)
conn.set_character_set("utf8");
cur = conn.cursor()

file = open('/home/chaojiansong/videobook/notinsvn/video_score_list.uniq', 'r')
out = open('/home/chaojiansong/videobook/notinsvn/video_tfvector', 'w')
cnt = 0
for line in file:
    if cnt % 6 == 0:
        video_id = line.rstrip()
        out.write('video: ' + video_id + '\n')
        cur.execute("select baike_tag from pop_history_baike_tags where video_id='" + video_id + "'")
        d = {}
        for record in cur.fetchall():
            tag = record[0]
            if tag in d:
                d[tag] = d[tag] + 1
            else:
                d[tag] = 1
        for tag in d:
            out.write('tag: ' + tag + '\n')
            out.write('tf: ' + str(d[tag]) + '\n')
    cnt = cnt + 1

out.close()
file.close()
cur.close()
conn.close()
